package com.lanou3g.musicenjoy.activities;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;

import com.lanou3g.musicenjoy.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created 辛鑫 dllo on 15/10/22.
 * mv播放界面
 */
public class ViedeoViewActivity extends Activity {
    @Bind(R.id.video_view)
    VideoView videoView;
    private String url;
    private MediaController mMediaController;
    private int mPositionWhenPaused = - 1;
    private Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //让屏幕横向显示
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.video_view_layout);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        url = intent.getStringExtra("url");
        Log.d("TAGGG", "onCreate() called with: " + "savedInstanceState = [" + url + "]");

        //该组件可以管理视频的播放,暂停等操作,不需要实现
        mMediaController = new MediaController(this);
        uri = Uri.parse(url);
        //videoView.setVideoURI(uri);
        videoView.setMediaController(mMediaController);
        //mMediaController.setMediaPlayer(videoView);
        //让videoView获得焦点
        //videoView.requestFocus();
        videoView.setVideoURI(uri);
        //开始播放
        videoView.start();
        //获得焦点
        videoView.requestFocus();
    }

//    @Override
//    protected void onStart() {
//        videoView.setVideoURI(uri);
//        videoView.start();
//        super.onStart();
//    }
//
//    @Override
//    protected void onPause() {
//        mPositionWhenPaused = videoView.getCurrentPosition();
//        videoView.stopPlayback();
//        super.onPause();
//    }
//
//    @Override
//    protected void onResume() {
//        if (mPositionWhenPaused >= 0) {
//            videoView.seekTo(mPositionWhenPaused);
//            mPositionWhenPaused = - 1;
//        }
//        super.onResume();
//    }
//
//    @Override
//    public void onCompletion(MediaPlayer mp) {
//        this.finish();
//    }
//
//    @Override
//    public boolean onError(MediaPlayer mp, int what, int extra) {
//        return false;
//    }
}
